package io.renren.modules.demo.algorithm;

import java.util.ArrayList;

public class CarScheduling
{
    private static ArrayList<Car> carArrayList;

    private static ArrayList<Warehouse> warehouseArrayList;

    private static int[][] distance;

    static
    {
        carArrayList = new ArrayList<>();
        warehouseArrayList = new ArrayList<>();
    }

    public static void Initialize()
    {
        carArrayList = new ArrayList<>();
        warehouseArrayList = new ArrayList<>();
    }

    public static ArrayList<Car> getCarArrayList()
    {
        return carArrayList;
    }

    public static void setCarArrayList(ArrayList<Car> carArrayList)
    {
        CarScheduling.carArrayList = carArrayList;
    }

    public static ArrayList<Warehouse> getWarehouseArrayList()
    {
        return warehouseArrayList;
    }

    public static void setWarehouseArrayList(ArrayList<Warehouse> warehouseArrayList)
    {
        CarScheduling.warehouseArrayList = warehouseArrayList;
    }

    public static int[][] getDistance()
    {
        return distance;
    }

    public static void setDistance(int[][] distance)
    {
        CarScheduling.distance = distance;
    }

    public static int CalculateDistance(Gene gene, Car car)
    {
        if(car.getCurrentLocation() == 0)
        {
            return Math.abs(warehouseArrayList.get(gene.getSerialNumber() - 1).getLocationX()) +
                    Math.abs(warehouseArrayList.get(gene.getSerialNumber() - 1).getLocationY());
        }
        else if(car.getCurrentLocation() == gene.getSerialNumber())
            return 0;
        else
        {
            return car.getCurrentLocation() < gene.getSerialNumber() ? distance[car.getCurrentLocation()][gene.getSerialNumber()] :
                    distance[gene.getSerialNumber()][car.getCurrentLocation()];
        }
    }

    public static int CalculateDistance(Car car)
    {
        if(car.getCurrentLocation() != 0)
            return Math.abs(CarScheduling.getWarehouseArrayList().get(car.getCurrentLocation() - 1).getLocationX()) +
                    Math.abs(CarScheduling.getWarehouseArrayList().get(car.getCurrentLocation() - 1).getLocationY());
        else
            return 0;
    }
}
